package middleware

import (
	"fmt"
	"github.com/e421083458/gin_scaffold/public"
	"github.com/gin-gonic/gin"
	"runtime/debug"
)

// Recovery 服务
func Recovery() gin.HandlerFunc {
	return func(c *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				public.ComLogNotice(c, "_com_panic", map[string]interface{}{
					"error": fmt.Sprint(err),
					"stack": string(debug.Stack()),
				})
			}
		}()
		c.Next()
	}
}
